home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part2 / 14818 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.7 KB

  1. Path: uwm.edu!caen!usenet
  2. From: Jonathan Mayer <jmayer@umich.edu>
  3. Newsgroups: comp.lang.c++
  4. Subject: Optimizing Const Strings
  5. Date: Mon, 01 Apr 1996 23:46:34 -0500
  6. Organization: University of Michigan Engineering, Ann Arbor
  7. Message-ID: <3160B12A.41C67EA6@umich.edu>
  8. NNTP-Posting-Host: swallow.eecs.umich.edu
  9. Mime-Version: 1.0
  10. Content-Type: text/plain; charset=us-ascii
  11. Content-Transfer-Encoding: 7bit
  12. X-Mailer: Mozilla 2.0 (X11; I; SunOS 4.1.3_U1 sun4m)
  13.  
  14. If I have an include file with a bunch of strings
  15. in it:
  16.  
  17.     typedef const char const * ConstStr;
  18.     ConstStr strA = "aaa";
  19.     ConstStr strB = "bbb";
  20.     ConstStr strC = "ccc";
  21.  
  22. And a program that uses only ONE of the aforementioned
  23. strings, all of the C-compilers I've tested (CSet++ and
  24. GCC) compile all three of the const strings into my
  25. program, even though only one of them was used.
  26.  
  27. Is there any way I can define these strings so that the
  28. linker will refuse to link an unused string?
  29.  
  30. (think: an include file listing lots of possible error 
  31. messages, but a C++ program that only uses some of 'em).
  32.  
  33. Back in the bad old C days, there was no problem having
  34. a bunch of #define'd strings, since only the utilized
  35. strings got instantiated in the program.  However,
  36. since I'm trying to be typesafe ... shouldn't there
  37. by a typesafe way to replicate this functionality in C++?
  38. Is there a trick I've missed?
  39.  
  40. Or it is a simple matter of: I'm declaring my data types
  41. correctly, but I'm expecting too much intelligence from
  42. the optimizer/linker?  
  43.  
  44. Sigh.  Want my cake and eating it too.
  45.  
  46. Please e-mail me replies ... USENET is too big and scary for me.
  47.  
  48. Thanks,
  49. Jonathan. <jmayer@umich.edu>
  50. -------------------------- sig free -------------------------
  51.